<template>
  <body class="poster">
    <div class="box">
      <div class="flexbox">
        <div style="padding-top: 35px; width: " class="transerve">
          <h1 class="title" style="pointer-events: none">
            虚拟宠物医院学习平台
          </h1>
        </div>
        <div class="log_btn">
          <div class="icon-box">
            <el-dropdown>
              <i class="el-icon-user" style="font-size: 30px"></i>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>
                  <p @click="dialogFormVisible = true">
                    用户名:{{ this.dialogform.username }}
                  </p>
                </el-dropdown-item>
                <el-dropdown-item>
                  <p>邮箱:{{ this.email }}</p>
                </el-dropdown-item>
                <el-dropdown-item>
                  <p @click="logout()">退出登录</p>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <div class="name-box">
            <span style="font-size: 15px"> {{ this.user }}</span>
          </div>
        </div>
      </div>
      <br />
      <el-carousel :interval="4000" type="card" class="pcard" height="400px">
        <el-carousel-item v-for="item in imgs" :key="item.id">
          <img :src="item.img" class="" width="100%" height="100%" />
        </el-carousel-item>
      </el-carousel>
      <el-row type="flex" class="row-btn" justify="space-around">
        <el-col :span="6"
          ><el-button class="btn" @click="to3D()">3D导览</el-button></el-col
        >
        <el-col :span="6"
          ><el-button class="btn" @click="toStudy()"
            >职能学习</el-button
          ></el-col
        >
        <el-col :span="6"
          ><el-button class="btn" @click="toTest()">学习测验</el-button></el-col
        >
        <el-col :span="6"
          ><el-button class="btn" @click="toGPT()">智能问诊</el-button></el-col
        >
      </el-row>

      <el-dialog
        title="修改用户名"
        :visible.sync="dialogFormVisible"
        width="30%">
        <el-form :model="dialogform">
          <el-form-item label="用户名" :label-width="formLabelWidth">
            <el-input
              v-model="dialogform.username"
              autocomplete="off"
              show-word-limit
              maxlength="5"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button
            type="primary"
            @click="
              dialogFormVisible = false
              changeName()
            "
            >确 定</el-button
          >
        </div>
      </el-dialog>
    </div>
  </body>
</template>

<script>
import { change } from '../api/index'
export default {
  name: 'home',
  data() {
    return {
      imgs: [
        {
          id: 1,
          img: require('../assets/3D.jpg'),
        },
        {
          id: 2,
          img: require('../assets/角色扮演.jpg'),
        },
        {
          id: 3,
          img: require('../assets/职能学习.jpg'),
        },
      ],
      user: '',
      email: '',
      formLabelWidth: '60px',
      dialogFormVisible: false,
      dialogform: {
        email: '',
        username: '',
      },
    }
  },
  created() {
    // this.email = this.$route.query.email || ''
    // this.user = this.$route.query.user || ''
    this.email = sessionStorage.getItem('email')
    this.user = sessionStorage.getItem('user')
    this.dialogform.username = this.user
    this.dialogform.email = this.email
    console.log('username', this.user)
  },
  mounted() {
    this.jugde3D()
  },
  methods: {
    changeName() {
      change(this.dialogform).then((res) => {
        if (res.data.code == '200') {
          this.user = this.dialogform.username
          sessionStorage.setItem('user', this.user)
          this.$message.success('修改成功！')
        }
      })
    },
    jugde3D() {
      if (this.$root.is3d == true) {
        this.$root.is3d = false
        window.location.reload()
        console.log('hhhh', this.$root.is3d)
      }
    },
    toTest() {
      this.$router.push({ path: '/test' })
      console.log('hh', this.$isThreeD)
    },
    toStudy() {
      this.$router.push({ path: '/study' })
    },
    toGPT() {
      this.$router.push({ path: '/inquiry' })
    },
    to3D() {
      this.$root.is3d = true
      this.$router.push({ path: '/threeD' })
    },
    logout() {
      this.$router.push({ path: '/' })
    },
  },
}
</script>

<style scoped>
.poster {
  background-image: url('../assets/空白.png');
  background-size: 100% 100%;
}

.box {
  text-align: center;
  font-family: 宋体;
}

.log_btn {
  margin-right: 30px;
  margin-top: 40px;
  z-index: 10;
  /* flex: 5%; */
  flex-direction: column;
  display: flex;
}
.icon-box {
  width: 40px;
  height: 40px;
  margin-left: 27px;
  /* line-height: 40px; */
  padding-top: 5px;
  box-sizing: border-box;
  border-radius: 50%;
  background-color: rgb(220, 220, 220);
}
.name-box {
  padding-top: 5px;
  line-height: 15px;
  width: 100px;
}
.title {
  /* position: relative; */
  margin-top: 10px;
}

.pcard {
  padding: 30px;
  margin: 20px;
  margin-top: 0px !important;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

.el-row {
  margin-bottom: 20px;
}

.el-col {
  /* background-color: red; */
  border-radius: 4px;
}

.row-btn {
  margin: 10px;
}

.btn {
  color: white;
  background-color: deepskyblue;
  width: 100%;
}
.flexbox {
  flex-direction: row;
  display: flex;
  padding-top: 10px;
}
.transerve {
  flex: 95%;
}
</style>
